/*
* Copyright 2023 NXP
* NXP Confidential and Proprietary. This software is owned or controlled by NXP and may only be used strictly in
* accordance with the applicable license terms. By expressly accepting such terms or by downloading, installing,
* activating and/or otherwise using the software, you are agreeing that you have read, and that you agree to
* comply with and are bound by, such license terms.  If you do not agree to be bound by the applicable license
* terms, then you may not retain, install, activate or otherwise use the software.
*/

#include "lvgl.h"
#include <stdio.h>
#include "gui_guider.h"
#include "events_init.h"
#include "widgets_init.h"
#include "custom.h"



int table_digital_clock_1_min_value = 05;
int table_digital_clock_1_hour_value = 8;
int table_digital_clock_1_sec_value = 50;
char g_table_date[20] = {0};
void setup_scr_table(lv_ui *ui)
{
	//Write codes table
	ui->table = lv_obj_create(NULL);
	lv_obj_set_size(ui->table, 130, 162);
	lv_obj_set_scrollbar_mode(ui->table, LV_SCROLLBAR_MODE_OFF);

	//Write style for table, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
	lv_obj_set_style_bg_opa(ui->table, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(ui->table, lv_color_hex(0x180fb9), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_grad_dir(ui->table, LV_GRAD_DIR_VER, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_grad_color(ui->table, lv_color_hex(0x25252b), LV_PART_MAIN|LV_STATE_DEFAULT);

	//Write codes table_datetext_1
	ui->table_datetext_1 = lv_label_create(ui->table);
	lv_label_set_text(ui->table_datetext_1, g_table_date);
	lv_obj_set_style_text_align(ui->table_datetext_1, LV_TEXT_ALIGN_CENTER, 0);
	lv_obj_add_flag(ui->table_datetext_1, LV_OBJ_FLAG_CLICKABLE);
	lv_obj_add_event_cb(ui->table_datetext_1, table_datetext_1_event_handler, LV_EVENT_ALL, NULL);
	lv_obj_set_pos(ui->table_datetext_1, 7, 51);
	lv_obj_set_size(ui->table_datetext_1, 115, 26);
	lv_obj_set_scrollbar_mode(ui->table_datetext_1, LV_SCROLLBAR_MODE_OFF);

	//Write style for table_datetext_1, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
	lv_obj_set_style_radius(ui->table_datetext_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_color(ui->table_datetext_1, lv_color_hex(0xffffff), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->table_datetext_1, &lv_font_montserratMedium_12, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_letter_space(ui->table_datetext_1, 1, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_opa(ui->table_datetext_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->table_datetext_1, 7, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_right(ui->table_datetext_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_left(ui->table_datetext_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_shadow_width(ui->table_datetext_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);

	//Write codes table_digital_clock_1
	static bool table_digital_clock_1_timer_enabled = false;
	char time_str[20]={0};
	sprintf(time_str, "%d:%02d", table_digital_clock_1_hour_value, table_digital_clock_1_min_value);
	ui->table_digital_clock_1 = lv_dclock_create(ui->table, time_str);
	if (!table_digital_clock_1_timer_enabled) {
		lv_timer_create(table_digital_clock_1_timer, 1000, NULL);
		table_digital_clock_1_timer_enabled = true;
	}
	lv_obj_set_pos(ui->table_digital_clock_1, 34, 77);
	lv_obj_set_size(ui->table_digital_clock_1, 61, 26);
	lv_obj_set_scrollbar_mode(ui->table_digital_clock_1, LV_SCROLLBAR_MODE_OFF);

	//Write style for table_digital_clock_1, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
	lv_obj_set_style_radius(ui->table_digital_clock_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_color(ui->table_digital_clock_1, lv_color_hex(0xffffff), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->table_digital_clock_1, &lv_font_montserratMedium_18, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_letter_space(ui->table_digital_clock_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->table_digital_clock_1, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_opa(ui->table_digital_clock_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->table_digital_clock_1, 7, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_right(ui->table_digital_clock_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_bottom(ui->table_digital_clock_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_left(ui->table_digital_clock_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_shadow_width(ui->table_digital_clock_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);

	//Write codes table_power
	ui->table_power = lv_textprogress_create(ui->table);
	lv_textprogress_set_range_value(ui->table_power, 0, 100, 0, 0);
	lv_textprogress_set_decimal(ui->table_power, 0);
	lv_textprogress_set_value(ui->table_power, 100);
	lv_obj_set_pos(ui->table_power, 90, -2);
	lv_obj_set_size(ui->table_power, 38, 21);
	lv_obj_set_scrollbar_mode(ui->table_power, LV_SCROLLBAR_MODE_OFF);

	//Write style for table_power, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
	lv_obj_set_style_radius(ui->table_power, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_color(ui->table_power, lv_color_hex(0xffffff), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->table_power, &lv_font_montserratMedium_10, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_letter_space(ui->table_power, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->table_power, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_opa(ui->table_power, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->table_power, 8, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_right(ui->table_power, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_bottom(ui->table_power, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_left(ui->table_power, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_shadow_width(ui->table_power, 0, LV_PART_MAIN|LV_STATE_DEFAULT);

	//Write codes table_setting
	ui->table_setting = lv_btn_create(ui->table);
	ui->table_setting_label = lv_label_create(ui->table_setting);
	lv_label_set_text(ui->table_setting_label, "Setting");
	lv_label_set_long_mode(ui->table_setting_label, LV_LABEL_LONG_WRAP);
	lv_obj_align(ui->table_setting_label, LV_ALIGN_CENTER, 0, 0);
	lv_obj_set_style_pad_all(ui->table_setting, 0, LV_STATE_DEFAULT);
	lv_obj_set_pos(ui->table_setting, 10, 124);
	lv_obj_set_size(ui->table_setting, 50, 31);
	lv_obj_set_scrollbar_mode(ui->table_setting, LV_SCROLLBAR_MODE_OFF);

	//Write style for table_setting, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
	lv_obj_set_style_bg_opa(ui->table_setting, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_border_width(ui->table_setting, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_radius(ui->table_setting, 5, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_shadow_width(ui->table_setting, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_color(ui->table_setting, lv_color_hex(0x2FDA64), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->table_setting, &lv_font_montserratMedium_10, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->table_setting, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);

	//Write codes table_start
	ui->table_start = lv_btn_create(ui->table);
	ui->table_start_label = lv_label_create(ui->table_start);
	lv_label_set_text(ui->table_start_label, "Start");
	lv_label_set_long_mode(ui->table_start_label, LV_LABEL_LONG_WRAP);
	lv_obj_align(ui->table_start_label, LV_ALIGN_CENTER, 0, 0);
	lv_obj_set_style_pad_all(ui->table_start, 0, LV_STATE_DEFAULT);
	lv_obj_set_pos(ui->table_start, 70, 124);
	lv_obj_set_size(ui->table_start, 50, 31);
	lv_obj_set_scrollbar_mode(ui->table_start, LV_SCROLLBAR_MODE_OFF);

	//Write style for table_start, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
	lv_obj_set_style_bg_opa(ui->table_start, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_border_width(ui->table_start, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_radius(ui->table_start, 5, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_shadow_width(ui->table_start, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_color(ui->table_start, lv_color_hex(0x2FDA64), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->table_start, &lv_font_montserratMedium_10, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->table_start, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);

	//Update current screen layout.
	lv_obj_update_layout(ui->table);

	
	//Init events for screen.
	events_init_table(ui);
}
